﻿using System;
using System.Collections;
using System.Data;
using Lib.Data;
using Lib.Utils;

namespace SysObj
{
    public class Bg_GiaNhap_ChiTiet
    {
        public DataTable GetDetail(DataLayer db, int IdGiaNhap)
        {
            return db.ExecDataTable("Sp_Bg_GiaNhap_ChiTiet", "Command,IdGiaNhap", "LoadData", IdGiaNhap);
        }

        public void Insert(DataLayer db, DataTable Data, int IdGiaNhap)
        {
            if (Data == null || Data.Rows.Count <= 0) return;

            string s_ParamName = "";
            object[] o_ParamValue = null;
            try
            {
                foreach (DataRow row in Data.Rows)
                {
                    ParamHolder.ClearAll();
                    ParamHolder.AddParam("Command", "Insert");
                    ParamHolder.AddParam("IdGiaNhap", IdGiaNhap);
                    ParamHolder.AddParam("IdHangHoa", Cvert.ToInt32(row["IdHangHoa"], 0));
                    ParamHolder.AddParam("DonGia", Cvert.ToDecimal(row["DonGia"], 0));
                    ParamHolder.AddParam("GhiChu", Cvert.ToString(row["GhiChu"], ""));
                    ParamHolder.GetParams(ref s_ParamName, ref o_ParamValue);
                    db.ExecNonQuery("Sp_Bg_GiaNhap_ChiTiet", s_ParamName, o_ParamValue);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void OnDelete(DataLayer db, int IdGiaNhap)
        {
            string s_ParamName = "";
            object[] o_ParamValue = null;
            try
            {
                ParamHolder.ClearAll();
                ParamHolder.AddParam("Command", "Delete");
                ParamHolder.AddParam("IdGiaNhap", IdGiaNhap);
                ParamHolder.GetParams(ref s_ParamName, ref o_ParamValue);
                db.ExecNonQuery("Sp_Bg_GiaNhap_ChiTiet", s_ParamName, o_ParamValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
